# 编译器设置
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra -g

# 源文件和目标文件
SRCS = main.cpp game.cpp snake.cpp
OBJS = $(SRCS:.cpp=.o)
TARGET = snakegame

# SDL2 配置
SDL2_CFLAGS = $(shell sdl2-config --cflags)
SDL2_LIBS = $(shell sdl2-config --libs)

# SDL2_mixer 配置
MIXER_CFLAGS = $(SDL2_CFLAGS)
MIXER_LIBS = -lSDL2_mixer

# NCURSES 配置
NCURSES_LIBS = -lncurses

# 包含路径
INCLUDES = $(SDL2_CFLAGS) $(MIXER_CFLAGS)

# 链接库
LIBS = $(SDL2_LIBS) $(MIXER_LIBS) $(NCURSES_LIBS)

# 编译规则
all: $(TARGET)

$(TARGET): $(OBJS)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

clean:
	rm -f $(OBJS) $(TARGET)
	rm *.dat

install-deps:
	sudo apt-get install libsdl2-dev libsdl2-mixer-dev libncurses-dev

run: $(TARGET)
	./$(TARGET)

.PHONY: all clean install-deps run
